﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using SpicIE;
using SpicIE.Controls;

namespace OpenSearch.Bho
{
    [ComVisible(true)]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    [Guid(Plugin_Guid)]
    [ProgId(Plugin_ProgId)]
    public class IeBho : Host
    {
        public static IeBho HostInstance;

        public IeBho()
        {
            HostInstance = this;

            ForceShowToolbar(typeof(IeOpenSearchToolbar));
        }

        public const string Plugin_Guid = "34BBEBDD-E4B5-43F3-8031-90AF7CE04D83";
        public const string Plugin_ProgId = "OpenSearch.SpicIE";

        internal static IEnumerable<IControlBase> RunOnceCOMRegistration()
        {
            TraceSink.TraceEvent(TraceEventType.Information, 0, "RunOnceRegisterCOMControls");

            var controls = new List<IControlBase>
                               {
                                   new IeOpenSearchToolbar()
                               };
            return controls;
        }

        [ComRegisterFunction]
        internal static void RegisterControls(Type typeToRegister)
        {
            SpicIE.Host.RegisterHost(typeToRegister, Plugin_Guid, Plugin_ProgId);

            SpicIE.Host.RegisterControls(RunOnceCOMRegistration());
        }

        [ComUnregisterFunction]
        internal static void UnregisterControls(Type typeToRegister)
        {
            SpicIE.Host.UnregisterHost(typeToRegister, Plugin_Guid);

            SpicIE.Host.UnregisterControls(RunOnceCOMRegistration());
        }
    }
}
